home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12700 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  55 lines

  1. Path: hops.cs.jhu.edu!lasher
  2. From: lasher@hops.cs.jhu.edu (John E. Davis)
  3. Newsgroups: comp.lang.c
  4. Subject: help with strcmp
  5. Date: 1 Apr 1996 21:39:32 GMT
  6. Organization: JHU computer science
  7. Message-ID: <4jpiek$lp6@blaze.cs.jhu.edu>
  8. NNTP-Posting-Host: hops.cs.jhu.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. For some reason when I try to compare the strings in the following 
  12. snippet I consistently get a core dump (running on a UNIX machine running 
  13. Solaris).  Could anyone point out what may be going wrong?  I have run it 
  14. through the debugger and that was no help at all for me.  here is the 
  15. code snippet:
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. void setup(FILE *);
  22.  
  23. void main(int argc, char *argv[])
  24. {
  25. char         buf[20], data[40], *buff, *arg, *fp;
  26. FILE         *handle, *dest;
  27. int         n;
  28.  
  29. handle = fopen(argv[1], "r");
  30. if(dest = fopen( "dbuild.out", "w")) setup(dest);
  31.  
  32. while(!feof(handle)) {
  33.     n = 0;
  34.     fp = fgets(data, 40, handle);
  35.     if ( strcasecmp(fp, "<action>\n") == 0)  /* the coredump is here */
  36.         parseAction(handle, dest); 
  37.     else if ( strcasecmp(fp, "<control>\n") == 0)
  38.         parseControl(handle, dest);
  39.     else if ( strcasecmp(fp, "<general>\n") == 0)
  40.         parseGeneral(handle, dest); 
  41.     printf("%s", data);
  42.      }
  43. fclose(dest);
  44.  
  45. }
  46.  
  47.  
  48. --
  49. John Davis
  50. lasher@hops.cs.jhu.edu
  51. http://hops.cs.jhu.edu/~lasher
  52.  
  53. UNIX is a very user-friendly operating system 
  54.  it's just picky about who it's friends with.
  55.